package com.whmall.service.crm.provider;

import com.whmall.component.entity.dto.OperatorReqDTO;
import com.whmall.component.entity.dto.PageReqDTO;
import com.whmall.component.entity.dto.PageRspDTO;
import com.whmall.service.crm.api.CompanyUserAddressApi;
import com.whmall.service.crm.entity.dto.company.*;
import com.whmall.service.crm.entity.dto.companyuser.CompanyUserAddressDTO;
import com.whmall.service.crm.module.company.service.CompanyUserAddressService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = CompanyUserAddressApi.class)
public class CompanyUserAddressProvider implements CompanyUserAddressApi {

    @Autowired
    private CompanyUserAddressService companyUserAddressService;

    @Override
    public CompanyUserAddressDTO getById(long id) {
        return companyUserAddressService.getById(id);
    }

    @Override
    public CompanyUserAddressAddRspDTO add(CompanyUserAddressAddReqDTO reqDTO) {
        return companyUserAddressService.add(reqDTO);
    }

    @Override
    public String update(CompanyUserAddressUpdateReqDTO reqDTO) {
        return companyUserAddressService.update(reqDTO);
    }

    @Override
    public void genInvoiceAddress(Long id, OperatorReqDTO operator) {
        if(companyUserAddressService.genInvoiceAddress(id, operator) != 0) {
            throw new IllegalArgumentException("生成收票地址失败，已存在相同的收票地址");
        }
    }

    @Override
    public void remove(Long id, OperatorReqDTO operator) {
        companyUserAddressService.remove(id, operator);
    }

    @Override
    public void setDefault(Long id, OperatorReqDTO operator) {
        companyUserAddressService.setDefault(id, operator);
    }

    @Override
    public List<CompanyUserAddressQueryRspDTO> list(CompanyUserAddressQueryReqDTO queryReqDTO) {
        return companyUserAddressService.list(queryReqDTO);
    }

    @Override
    public PageRspDTO<CompanyUserAddressQueryRspDTO> list(PageReqDTO pageReqDTO, CompanyUserAddressQueryReqDTO reqDTO) {
        return companyUserAddressService.list(pageReqDTO, reqDTO);
    }

}
